package com.briup.cms.web.controller;

import com.briup.cms.bean.Category;
import com.briup.cms.service.ICategoryService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "栏目管理接口")
@RestController
@RequestMapping("/cms_category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @ApiOperation("查询所有")
    @GetMapping("findAll")
    public Message findAll(){
        List<Category> list =categoryService.findAll();
        return MessageUtil.success(list);
    }

    @ApiOperation("保存或更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Category category){
        categoryService.saveOrUpdate(category);
        return MessageUtil.success("操作成功");
    }

    @ApiOperation("删除")
    @PostMapping("delete")
    public Message delete(@RequestParam @ApiParam(name = "id",value="栏目Id",required=true)long id){
        categoryService.delete(id);
            return MessageUtil.success("成功删除");

    }

}
